// pages/exchangedetail/exchangedetail.js

const host = require('../../config.js').host;
const network = require('../../utils/network.js');
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    host:host,
    goodsId:'',
    detailDic:{}
  },
  getDetail() {
    let that = this; 
    network.requestGet(host + '/xcx/goods/goods-info', {
      "goodsId":that.data.goodsId
    }, res => { 
      if (res.data.code == 200) {
        that.setData({
          detailDic: res.data.data,
        }) 
      } else {
        wx.showToast({
          title: res.data.msg ? res.data.msg : '请求失败',
          icon: "none",
          duration: 1200
        })
      }                                 
    })
  },
  postExchangeData() { 
    let that = this;
    network.requestPost(host + '/xcx/customer-prize/exchange-prize', {
      "goodsId": that.data.goodsId
    }, res => { 
      if (res.data.code == 200) {
        wx.showToast({
          title: '兑换成功',
        })
        setTimeout(() => {
          wx.navigateBack({
            delta: 0,
          })
        }, 1500);
      } else {
        wx.showToast({
          title: res.data.msg ? res.data.msg : '请求失败',
          icon: "none",
          duration: 1200
        })
      }                           
    })
  },
  /**
   * 生命周期函数--监听页面加载/xcx/ goods /goods-info
   */
  onLoad: function (options) {
    this.setData({
      goodsId:options.goodsId
    })
    this.getDetail()
     
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})